<template>
<Modal
	v-model="show"
	title="科目信息"
	:width="700"
	>
	<Form :model="info" :label-width="150" style="width: 100%" :rules="ruleValidate" ref="form">
		
		<Row>
			<Col>
				<FormItem label="部门名称：" prop="name">
					<Input v-model="info.name" placeholder="" style="width: 240px;"></Input>
				</FormItem>
			</Col>
			<Col>
				<FormItem label="排序：">
					<Input v-model="info.sort" placeholder="" style="width: 240px;"></Input>
					<p style="color: #999;">请输入0-999整数，0为优先</p>
				</FormItem>
			</Col>
			<Col>
				<FormItem label="上级分类：">
					<bumen_filter v-model="info.parent_id" style="width: 240px;" :has_default="1" :is_update="show"></bumen_filter>
					<p style="color: #999;">不选择分类默认为一级分类</p>
				</FormItem>
			</Col>
			<Col>
				<FormItem label="是否显示：">
					 <i-switch v-model="info.is_enable" :true-value="1" :false-value="0" size="large"></i-switch>
				</FormItem>
			</Col>
		</Row>
		
	</Form>

	<div slot="footer" style="text-align: center;">
		<Button type="success" size="large" @click="handleSubmit('form')">提交</Button>
	</div>
</Modal>
</template>

<script>
import bumen_filter from '@/themes/components/bumen_filter';

export default {
	name: 'bumen_info',
	components:{
		bumen_filter
	},
	data(){
		return {
			show:false,
			def_info:{
				name:'',
				sort:'10',
				parent_id:0,
				is_enable:1,
				id:0
			},
			info:{
				name:'',
				sort:'10',
				parent_id:0,
				is_enable:1,
				id:0
			},
			ruleValidate:{
				name:[
					{ required: true, message: '请填写部门名称', trigger: 'blur' }
				],
				
			},
		};
	},
	props:['value','cinfo'],
	created(){
		this.show = this.value;
		
	},
	watch:{
		value(val){
			this.show = val;
		},
		show(val){
			this.$emit('input',val);
		},
		cinfo:{
			handler(val){
				if(typeof(val)!='object'){
					this.info = this._getData(this.def_info);
					return;
				}
				for(var i in this.info){
					if(typeof(val[i])!='undefined'){
						this.info[i] = val[i];
					}
					else{
						this.info[i] = this.def_info[i];
					}
				}
				this.info.is_enable = parseInt(this.info.is_enable);
				
			},
			deep:true
		}
	},
	methods: {
		 handleSubmit(name) {
			var self = this;
			this.$refs[name].validate((valid) => {
				if(valid) {
					self.save();
				}
			})
		},
		save(){
			var self = this;
			
			var postdata = this.info;
			
			
			Whttp.load('User/Bumen/save',postdata,function(res){
				self.$Message.info('提交成功');
				self.$emit('success',res);
				self.show = false;
			});
		}
	}
}
</script>
<style scoped>

</style>